package ui.fragment.minefragment;

import android.support.v4.app.Fragment;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.just.agentweb.AgentWeb;
import com.just.agentweb.AgentWebView;

import java.util.HashMap;
import java.util.Map;

import base.BaseBean;
import base.fragment.BaseNetFragment;
import bean.ServiceAgreementBean;
import student.andlei.com.student.R;
import ui.fragment.MineFragment;
import utils.GsonUtils;

/**
 * 积分规则
 */
public class IntegralRuleFragment extends BaseNetFragment {
    private AgentWeb mAgentWeb;
    private AgentWebView agentWebView;
    private ImageView iv_back;
    private TextView tv_info;
    public static Fragment getInstance() {
        return new IntegralRuleFragment();
    }
    @Override
    public void success(String action, BaseBean baseBean) {
        if(baseBean.code == 200){
            ServiceAgreementBean agreementBean = (ServiceAgreementBean) GsonUtils.getInstance(context).parseComplexJArrayByCommon(baseBean,ServiceAgreementBean.class);
            mAgentWeb = AgentWeb.with(IntegralRuleFragment.this)
                    .setAgentWebParent(agentWebView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
                    .useDefaultIndicator()
                    .createAgentWeb()
                    .ready()
                    .go(agreementBean.url);
        }else {
            toast(baseBean.msg);
        }
    }

    @Override
    public void error(String action, Throwable e) {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_integralrule;
    }

    @Override
    protected void findViews() {
        agentWebView = getView(R.id.AgentWebView);
        iv_back = getView(R.id.img_back);
//        tv_info = getView(R.id.tv_rule_info);
    }

    @Override
    protected void formatViews() {
        iv_back.setOnClickListener(this);
    }

    @Override
    protected void formatData() {
//        tv_info.setText("如何获得积分？\n" +
//                "\n每日上课、作业、错题、笔记等操作都可以获取积分。获得的积分可以在全班同学中进行排名。具体的积分规则及获得方式如下：\n\n" +
//                "\n上课积分\n" +
//                "\n每日上课可领1积分\n\n" +
//                "\n作业积分\n" +
//                "\n每做完一份作业可获得2积分，错题订正可获得1积分");
            loadData();
    }
    private void loadData(){
        //1服务协议 2积分规则 3关于我们
        Map<String,Object> map = new HashMap<>();
        map.put("type",2);
        post("common/article",map,BaseBean.class,false);
    }
    @Override
    protected void getBundle() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.img_back:
                ((MineFragment)(this.getParentFragment())).GojumpMyPointsFragment();
                break;
        }
    }
    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if(!hidden){
            loadData();
        }
    }
}
